home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / comm / tcp / hserv.lha / hserv / main / hconf.rexx < prev    next >
OS/2 REXX Batch file  |  1999-05-24  |  18KB  |  517 lines

  1. /* hconf.rexx - hserv preferences  editor */
  2.  
  3. signal on halt
  4. signal on break_c
  5.  
  6. call start
  7. call readArguments
  8. call initGlobal
  9. call openGUI
  10. call setMenuList
  11. call openMainWin
  12. call setServer
  13. if readConfig()~=0 then call status global.error
  14. else call status "File" global.file "read"
  15. call setMainGadgets
  16. call handle
  17. call closeGui
  18. exit
  19. /***************************************************************************/
  20. error: procedure expose global. sigl
  21. parse arg code
  22.     if RXWIZERR~="RXWIZERR" then string = GetRxWizString(1001)":" RXWIZERR || d2c(10)
  23.     else string=""
  24.     string= string || GetRxWizString(code) || d2c(10) || GetRxWizString(1002)":" SIGL-1
  25.     say string
  26.     exit
  27. /**************************************************************************/
  28. start: procedure expose global.
  29.     l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  30.     if AddLibrary("rexxsupport.library","rxsocket.library","rxwiz.library")~=0 then exit
  31.     global.program="HservPrefs"
  32.     global.ver="10.1"
  33.     global.prg=ProgramName("NOEXT")
  34.     global.author="Alfonso Ranieri"
  35.     global.hotkey="rawkey ctrl alt h"
  36.     global.path=PathPart(ProgramName("FULL"))
  37.     global.surface=AddPart(global.path,global.prg".wizard")
  38.     global.catalog=global.prg".catalog"
  39.     global.selected=0
  40.     global.server=""
  41.     global.snapshot=0
  42.     return
  43. /***************************************************************************/
  44. readArguments: procedure expose global.
  45.     parm.1.value=""
  46.     if ~ReadArgs("FILE,PUBSCREEN/K,SERVER/K") then do
  47.         call PrintFault()
  48.         exit
  49.     end
  50.     if parm.2.flag then global.server=parm.2.value
  51.     if parm.0.flag then global.file=parm.0.value
  52.     else do
  53.         f="conf/hserv.conf"
  54.         if exists(f) then global.file=f
  55.         else global.file=""
  56.     end
  57.     global.screen=parm.1.value
  58.     return
  59. /***************************************************************************/
  60. initGlobal: procedure expose global.
  61.     global.HostName             = ""
  62.     global.Port                    = 80
  63.     global.Pri                    = 0
  64.     global.Status                = "OPENED"
  65.     global.DocumentDir            = ""
  66.     global.DocumentIndex        = ""
  67.     global.CgiDir                = ""
  68.     global.TransferLog            = "OFF"
  69.     global.TransferFile            = ""
  70.     global.ErrorLog                = "SYS"
  71.     global.ErrorFile            = ""
  72.     global.Auth                    = ""
  73.     global.RejectedIP            = ""
  74.     global.MimeFile                = ""
  75.     global.KeepAlive            = 1
  76.     global.KeepAliveTimeout        = 50
  77.     global.Timeout                = 300
  78.     global.HostNameLookups        = "OFF"
  79.     global.Ident                = "OFF"
  80.     global.OnlyAmigaClient        = "OFF"
  81.     global.DefImage                = "ON"
  82.     global.Admin                = ""
  83.     global.Specials                = ""
  84.     global.Handlers                = ""
  85.     global.VirtualHosts            = ""
  86.     global.Errors                = ""
  87.     return
  88. /***************************************************************************/
  89. readConfig: procedure expose global.
  90.  
  91.     if global.file="" then do
  92.         global.error="No config file found"
  93.         return 6
  94.     end
  95.  
  96.     call status "Reading file" global.file "..."
  97.     lines=ParseConfig(global.file,"CONF")
  98.     if lines==-1 then do
  99.         global.error="Config file '"global.file"' not found"
  100.         return 5
  101.     end
  102.  
  103.     err=0
  104.     do i=0 to lines-1 while err=0
  105.         opt=conf.i
  106.         arg=conf.i.value
  107.         argu=upper(arg)
  108.         select
  109.             when opt=="HOSTNAME" then global.HostName=arg
  110.             when opt=="PORT" then
  111.                 if ~DataType(arg,"N") then err=2
  112.                 else if arg<1 | arg>65535 then err=2
  113.                      else global.Port=arg
  114.             when opt=="STATUS" then
  115.                 if argu~="OPENED" & argu~= "PAUSED" & argu~= "CLOSED" then err=1
  116.                 else global.Status=argu
  117.             when opt=="PRI" then
  118.                 if ~DataType(arg,"N") then err=2
  119.                 else if arg<-128 | arg>128 then err=2
  120.                      else global.Pri=arg
  121.             when opt=="DOCUMENTDIR" then global.DocumentDir=arg
  122.             when opt=="DOCUMENTINDEX" then global.DocumentIndex=arg
  123.             when opt=="CGIDIR" then global.CgiDir=arg
  124.             when opt=="AUTH" then global.Auth=arg
  125.             when opt=="HOSTNAMELOOKUPS" then
  126.                 if argu~="ON" & argu~= "OFF" then err=1
  127.                 else global.HostNameLookups=argu
  128.             when opt=="ERRORLOG" then
  129.                 if argu~="ON" & argu~= "OFF" & argu~="SYS" then err=1
  130.                 else global.ErrorLog=argu
  131.             when opt=="ERRORFILE" then global.ErrorFile=arg
  132.             when opt=="TRANSFERLOG" then
  133.                 if argu~="ON" & argu~= "OFF" & argu~="SYS" then err=1
  134.                 else global.TransferLog=argu
  135.             when opt=="TRANSFERFILE" then global.TransferFile=arg
  136.             when opt=="IDENT" then
  137.                 if argu~="ON" & argu~= "OFF" then err=1
  138.                 else global.ident=argu
  139.             when opt=="KEEPALIVE" then
  140.                 if ~DataType(arg,"N") then err=2
  141.                 else global.KeepAlive=arg
  142.             when opt=="KEEPALIVETIMEOUT" then
  143.                 if ~DataType(arg,"N") then err=2
  144.                 else global.KeepAliveTimeout=arg
  145.             when opt=="TIMEOUT" then
  146.                 if ~DataType(arg,"N") then err=2
  147.                 else global.Timeout=arg
  148.             when opt=="REJECTEDIP" then global.RejectedIP=arg
  149.             when opt=="MIMEFILE" then global.MimeFile=arg
  150.             when opt=="ONLYAMIGACLIENT" then
  151.                 if argu~="ON" & argu~= "OFF" then err=1
  152.                 else global.OnlyAmigaClient=argu
  153.             when opt=="DEFIMAGE" then
  154.                 if argu~="ON" & argu~= "OFF" then err=1
  155.                 else global.DefImage=argu
  156.             when opt=="ADMIN" then global.admin=arg
  157.             when opt=="SPECIALS" then global.Specials=arg
  158.             when opt=="HANDLERS" then global.Handlers=arg
  159.             when opt=="VIRTUALHOSTS" then global.VirtualHosts=arg
  160.             when opt=="ERRORS" then global.Errors=arg
  161.             otherwise err=3
  162.         end
  163.     end
  164.     i=i-1
  165.  
  166.     select
  167.         when err==1 then global.error="bad option '"arg"' in line" conf.i.line
  168.         when err==2 then global.error="bad number '"arg"' in line" conf.i.line
  169.         when err==3 then global.error="unknown option '"opt"' in line" conf.i.line
  170.         when err==4 then global.error="bad argument '"arg"' in line" conf.i.line
  171.         otherwise nop
  172.     end
  173.     if err~=0 then return err
  174.  
  175.     if global.ErrorFile=="" & global.ErrorLog~="SYS" then global.ErrorLog="OFF"
  176.     if global.TransferFile=="" & global.TransferLog~="SYS" then global.TransferLog="OFF"
  177.     if global.RejectedIP~="" then global.HostNameLookups="ON"
  178.  
  179.     return 0
  180. /***************************************************************************/
  181. openGUI: procedure expose global.
  182.     call SetStacks(,8192)
  183.     s.pubscreen=global.screen
  184.     s.fallback=1
  185.     s.catalog=global.catalog
  186.     s.AppName=global.prg
  187.     s.AppIcon=AddPart(global.path,global.prg)
  188.     s.CxTitle=global.program global.ver "©" global.author
  189.     s.CxDescr="hserv preferences editor"
  190.     s.MasterWin="MW"
  191.     s.AutoClose=1
  192.     res=OpenSurface(global.surface,"S")
  193.     if res~=0 then call error(res)
  194.     global.ss=SurfaceSignal("S")
  195.     mw.ID=1
  196.     mw.Gads=118
  197.     mw.nowindow=1
  198.     res=OpenWindow("S","MW")
  199.     if res~=0 then call error(res)
  200.     return
  201. /***************************************************************************/
  202. closeGui: procedure expose global.
  203.     call CloseWindow("S","MW")
  204.     if global.snapshot then call SnapShot("S")
  205.     return
  206. /***************************************************************************/
  207. setMenuList: procedure expose global.
  208.     list.0="Host";list.0.pen=1;list.0.spen=2
  209.     list.1="Conns";list.1.pen=1;list.1.spen=2
  210.     list.2="Docs";list.2.pen=1;list.2.spen=2
  211.     list.3="Config";list.3.pen=1;list.3.spen=2
  212.     list.4="Specials";list.4.pen=1;list.4.spen=2
  213.     list.5="Log";list.5.pen=1;list.5.spen=2
  214.     list.6="Flags";list.6.pen=1;list.6.spen=2
  215.     list.7="About";list.7.pen=1;list.7.spen=2
  216.     global.maxmenu=7
  217.     set.list="LIST"
  218.     set.selected=global.selected
  219.     call SetWizAttrs("S","MW","MENU","SET")
  220.     drop set.
  221.     set.page=global.selected
  222.     call SetWizAttrs("S","MW","PAGER","SET")
  223.     return
  224. /***************************************************************************/
  225. setMainGadgets: procedure expose global.
  226.     set.string=global.hostname
  227.     call SetWizAttrs("S","MW","HOSTNAME","SET")
  228.     set.string=global.admin
  229.     call SetWizAttrs("S","MW","ADMIN","SET")
  230.     set.string=global.specials
  231.     call SetWizAttrs("S","MW","SPECIALS","SET")
  232.     set.string=global.handlers
  233.     call SetWizAttrs("S","MW","HANDLERS","SET")
  234.     set.string=global.VirtualHosts
  235.     call SetWizAttrs("S","MW","VIRTUALHOSTS","SET")
  236.     set.string=global.Errors
  237.     call SetWizAttrs("S","MW","ERRORS","SET")
  238.     set.string=global.documentdir
  239.     call SetWizAttrs("S","MW","DOCUMENTDIR","SET")
  240.     set.string=global.cgidir
  241.     call SetWizAttrs("S","MW","CGIDIR","SET")
  242.     set.string=global.documentindex
  243.     call SetWizAttrs("S","MW","DOCUMENTINDEX","SET")
  244.     set.string=global.auth
  245.     call SetWizAttrs("S","MW","AUTH","SET")
  246.     set.string=global.rejectedip
  247.     call SetWizAttrs("S","MW","REJECTEDIP","SET")
  248.     set.string=global.mimefile
  249.     call SetWizAttrs("S","MW","MIMEFILE","SET")
  250.     set.string=global.transferfile
  251.     call SetWizAttrs("S","MW","TRANSFERFILE","SET")
  252.     set.string=global.errorfile
  253.     call SetWizAttrs("S","MW","ERRORFILE","SET")
  254.     set.string=global.documentdir
  255.     call SetWizAttrs("S","MW","DOCUMENTDIR","SET")
  256.     drop set.
  257.     set.integer=global.port
  258.     call SetWizAttrs("S","MW","PORT","SET")
  259.     set.integer=global.KeepAlive
  260.     call SetWizAttrs("S","MW","KEEPALIVE","SET")
  261.     set.integer=global.KeepAliveTimeout
  262.     call SetWizAttrs("S","MW","KEEPALIVETIMEOUT","SET")
  263.     set.integer=global.timeout
  264.     call SetWizAttrs("S","MW","TIMEOUT","SET")
  265.     set.integer=global.pri
  266.     call SetWizAttrs("S","MW","PRI","SET")
  267.     drop set.
  268.     w.OPENED=0;w.PAUSED=1;w.CLOSED=2
  269.     t=global.status
  270.     set.active=w.t
  271.     call SetWizAttrs("S","MW","STATUS","SET")
  272.     w.ON=0;w.OFF=1;w.SYS=2
  273.     t=global.transferlog
  274.     set.active=w.t
  275.     call SetWizAttrs("S","MW","TRANSFERLOG","SET")
  276.     e=global.errorlog
  277.     set.active=w.e
  278.     call SetWizAttrs("S","MW","ERRORLOG","SET")
  279.     drop set.
  280.     set.disabled=a>0
  281.     call SetWizAttrs("S","MW","TRANSFERFILE","SET")
  282.     call SetWizAttrs("S","MW","TRANSFERFILEPOP","SET")
  283.     set.disabled=b>0
  284.     call SetWizAttrs("S","MW","ERRORFILE","SET")
  285.     call SetWizAttrs("S","MW","ERRORFILEPOP","SET")
  286.     drop set.
  287.     set.checked=global.hostnamelookups="ON"
  288.     call SetWizAttrs("S","MW","HOSTNAMELOOKUPS","SET")
  289.     set.checked=global.ident="ON"
  290.     call SetWizAttrs("S","MW","IDENT","SET")
  291.     set.checked=global.onlyamigaclient="ON"
  292.     call SetWizAttrs("S","MW","ONLYAMIGACLIENT","SET")
  293.     set.checked=global.DefImage="ON"
  294.     call SetWizAttrs("S","MW","DEFIMAGE","SET")
  295.     return
  296. /***************************************************************************/
  297. handle: procedure expose global.
  298.     if global.server~="" then
  299.         call SetClip("HCONF_"global.server,pragma("ID"))
  300.     stop=0
  301.     ctrl_c=2**12
  302.     ctrl_d=2**13
  303.     ctrl_e=2**14
  304.     ctrl_f=2**15
  305.     global.signals=or(global.ss,ctrl_c,ctrl_d,ctrl_e,ctrl_f)
  306.     do while ~stop
  307.         mask=Wait(global.signals)
  308.         if and(mask,ctrl_c)~=0 then leave
  309.         if and(mask,ctrl_d)~=0 then call IconifySurface("S",1)
  310.         if and(mask,ctrl_e)~=0 then call IconifySurface("S",0)
  311.         if and(mask,ctrl_f)~=0 then call setServer
  312.         if and(mask,global.ss)~=0 then stop=handleGUI()
  313.         call setServer
  314.     end
  315.     if global.server~="" then do
  316.         call SetClip("HCONF_"global.server,"")
  317.     end
  318.     return
  319. /**************************************************************************/
  320. handleGUI: procedure expose global.
  321.     handle.wait=0
  322.     res=HandleSurface("S","HANDLE")
  323.     if res~=0 then call error(res)
  324.     do i=0 to handle.imsg-1
  325.         select
  326.             when handle.i.class="VANILLAKEY" then call GadgetKey("S",handle.i.window,handle.i.code,handle.i.qualifier)
  327.             when handle.i.class="RAWKEY" then do
  328.                 shift=handle.i.qualifier~=32768
  329.                 if handle.i.code=76 | handle.i.code=77 then do
  330.                     if handle.i.code=77 & global.selected<global.maxmenu then
  331.                         if shift then global.selected=global.maxmenu
  332.                         else global.selected=global.selected+1
  333.                     if handle.i.code=76 & global.selected>0 then
  334.                         if shift then global.selected=0
  335.                         else global.selected=global.selected-1
  336.                     set.selected=global.selected
  337.                     set.visible=set.selected
  338.                     call SetWizAttrs("S","MW","MENU","SET")
  339.                     drop set.;set.page=global.selected
  340.                     call SetWizAttrs("S","MW","PAGER","SET")
  341.                 end
  342.             end
  343.             when handle.i.class="MENUPICK" then do
  344.                 select
  345.                     when handle.i.objectID="MQUIT" then do
  346.                         call CloseWindow("S",handle.i.window)
  347.                         return 1
  348.                     end
  349.                     when handle.i.ObjectID="MHIDE" then call IconifySurface("S",1)
  350.                     otherwise if handle.i.ObjectID~="" & handle.i.config~="" then interpret handle.i.config
  351.                 end
  352.             end
  353.             when handle.i.class="IDCMPUPDATE" then do
  354.                 select
  355.                     when handle.i.ObjectID="CANCEL" then do
  356.                         call CloseWindow("S",handle.i.window)
  357.                         return 1
  358.                     end
  359.                     when handle.i.ObjectID="CLOSESERVER" then do
  360.                         call sendServer("QUIT")
  361.                         call CloseWindow("S",handle.i.window)
  362.                         return 1
  363.                     end
  364.                     when handle.i.ObjectID="DOCUMENTINDEXPOP" then do
  365.                         d=reqF(AddPart(global.documentdir,global.documentindex),0)
  366.                         if d~="" then do
  367.                             global.documentindex=FilePart(d)
  368.                             set.string=global.documentindex
  369.                             call SetWizAttrs("S","MW","DOCUMENTINDEX","SET")
  370.                         end
  371.                     end
  372.                     otherwise if handle.i.ObjectID~="" & handle.i.config~="" then interpret handle.i.config
  373.                 end
  374.             end
  375.             otherwise nop
  376.         end
  377.     end
  378.     return 0
  379. /**************************************************************************/
  380. reqF: procedure expose global.
  381. parse arg f,onlyDrawer,save
  382.     f.SaveMode=save==1
  383.     f.window="S/MW"
  384.     if onlyDrawer then f.Drawer=f
  385.     else f.Drawer=PathPart(f)
  386.     f.File=FilePart(f)
  387.     f.DrawersOnly=onlyDrawer
  388.     if ReqFile("F")=0 then
  389.         if onlyDrawer then return f.drawer
  390.         else return addpart(f.drawer,f.file)
  391.     else return ""
  392. /**************************************************************************/
  393. status: procedure expose global.
  394. parse arg msg
  395.     set.text=msg
  396.     call SetWizAttrs("S","MW","INFO","SET")
  397.     return
  398. /**************************************************************************/
  399. writeFile: PROCEDURE EXPOSE global.
  400. parse arg file
  401.     call LockWindow("S","MW")
  402.     call status "Wrinting configuration..."
  403.     if ~open("OUT",file,"W") then do
  404.         call UnLockWindow("S","MW")
  405.         call status "Can't open file '"file"'"
  406.         return 0
  407.     end
  408.  
  409.     conf="## hserv configuration file"d2c(10)"## created by" global.program"/"global.ver formatdate(,"%a, %d %b %Y %X")d2c(10)"##"d2c(10)
  410.  
  411.     if global.HostName~="" then conf = conf || left("HostName",20) global.hostname || "A"x
  412.     if global.Admin~="" then conf = conf || left("Admin",20) global.Admin || "A"x
  413.     if global.Port~="" then conf = conf || Left("Port",20) global.Port || "A"x
  414.     if global.Pri~="" then conf = conf || Left("Pri",20) global.Pri || "A"x
  415.     if global.DocumentDir~="" then conf = conf || Left("DocumentDir",20) global.DocumentDir || "A"x
  416.     if global.DocumentIndex~="" then conf = conf || Left("DocumentIndex",20) global.DocumentIndex || "A"x
  417.     if global.CgiDir~="" then conf = conf || Left("CgiDir",20) global.CgiDir || "A"x
  418.     if global.RejectedIP~="" then conf = conf || Left("RejectedIP",20) global.RejectedIP || "A"x
  419.     if global.Auth~="" then conf = conf || Left("Auth",20) global.Auth || "A"x
  420.     if global.MimeFile~="" then conf = conf || Left("MimeFile",20) global.MimeFile || "A"x
  421.     if global.TransferLog~="" then conf = conf || Left("TransferLog",20) global.TransferLog || "A"x
  422.     if global.TransferFile~="" then conf = conf || Left("TransferFile",20) global.TransferFile || "A"x
  423.     if global.ErrorLog~="" then conf = conf || Left("ErrorLog",20) global.ErrorLog || "A"x
  424.     if global.ErrorFile~="" then conf = conf || Left("ErrorFile",20) global.ErrorFile || "A"x
  425.     if global.Status~="" then conf = conf || Left("Status",20) global.Status || "A"x
  426.     if global.KeepAlive~="" then conf = conf || Left("KeepAlive",20) global.KeepAlive || "A"x
  427.     if global.KeepAliveTimeout~="" then conf = conf || Left("KeepAliveTimeout",20) global.KeepAliveTimeout || "A"x
  428.     if global.Timeout~="" then conf = conf || Left("Timeout",20) global.Timeout || "A"x
  429.     if global.HostnameLookups~="" then conf = conf || Left("HostnameLookups",20) global.HostnameLookups || "A"x
  430.     if global.Ident~="" then conf = conf || Left("Ident",20) global.Ident || "A"x
  431.     if global.OnlyAmigaClient~="" then conf = conf || Left("OnlyAmigaClient",20) global.OnlyAmigaClient || "A"x
  432.     if global.DefImage~="" then conf = conf || Left("DefImage",20) global.DefImage || "A"x
  433.     if global.Special~="" then conf = conf || left("Specials",20) global.Specials || "A"x
  434.     if global.Handlers~="" then conf = conf || left("Handlers",20) global.Handlers || "A"x
  435.     if global.VirtualHosts~="" then conf = conf || left("VirtualHosts",20) global.VirtualHosts || "A"x
  436.     if global.Errors~="" then conf = conf || left("Errors",20) global.Errors || "A"x
  437.     if WriteCh("OUT",conf)~=length(conf) then call status "Error writing"
  438.     else call status "Configuration saved"
  439.     call close("OUT")
  440.     call UnLockWindow("S","MW")
  441.     return 1
  442. /**************************************************************************/
  443. dirReq: procedure expose global.
  444. parse arg dir
  445.     interpret "d=reqF(global."dir",1)"
  446.     if d~="" then do
  447.         interpret "global."dir"=d"
  448.         set.string=d
  449.         call SetWizAttrs("S","MW",dir,"SET")
  450.     end
  451.     return
  452. /**************************************************************************/
  453. fileReq: procedure expose global.
  454. parse arg file
  455.     interpret "d=reqF(global."file",0)"
  456.     if d~="" then do
  457.         interpret "global."file"=d;set.string=global."file
  458.         call SetWizAttrs("S","MW",file,"SET")
  459.     end
  460.     return
  461. /**************************************************************************/
  462. menuOpen: procedure expose global.
  463.     d=reqF(global.file,0)
  464.     if d="" then return
  465.     global.file=d
  466.     call initGlobal
  467.     res=readConfig()
  468.     call setMainGadgets
  469.     if res~=0 then call status global.error
  470.     else call status "File" global.file "read"
  471.     return
  472. /**************************************************************************/
  473. menuSaveAs: procedure expose global.
  474.     f=reqF(global.file,0,1)
  475.     if f="" then return
  476.     if writeFile(f) then do
  477.         global.file=f
  478.         call status "File" global.file "saved"
  479.         call sendServer("CONF" f)
  480.     end
  481.     return
  482. /**************************************************************************/
  483. menuRestore:procedure expose global.
  484.     call initGlobal
  485.     res=readConfig()
  486.     call setMainGadgets
  487.     if res~=0 then call status global.error
  488.     else call status "File" global.file "read"
  489.     return
  490. /**************************************************************************/
  491. openMainWin: procedure expose global.
  492.     mw.Title="HservPrefs ©" global.author
  493.     if global.server~="" then mw.Title=mw.Title "[for" global.server"]"
  494.     mw.MaxHeight=0
  495.     res=OpenWindow("S","MW")
  496.     if res~=0 then call error(res)
  497.     return
  498. /**************************************************************************/
  499. sendServer: procedure expose global.
  500. parse arg msg
  501.     if show("P",global.server) then do
  502.         ADDRESS value(global.server)
  503.         msg
  504.     end
  505.     return
  506. /**************************************************************************/
  507. setServer: procedure expose global.
  508.     set.Page=show("P",global.server)
  509.     call SetWizAttrs("S","MW","CLOSESERVERPAGER","SET")
  510.     return
  511. /**************************************************************************/
  512. halt:
  513. break_c:
  514.     exit
  515. /**************************************************************************/
  516. /*$VER: hconf.rexx 12.1 (14.5.99)*/
  517.